/**
 * @author CH_ywx
 * @Date 2023-06-02
 * @Description
 */
package io.xccit.controller;

import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *@author CH_ywx
 *@Date 2023-06-02
 *@Description 权限异常处理器,防止异常信息直接返回到前端页面
 */
@ControllerAdvice
public class PermissionsExceptionHandler {
    /**
     * @param e 捕获到的异常信息
     * @return 返回到前端的信息
     */
    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    public String unauthorizedException(Exception e){
        return "当前用户无权限!";
    }

    /**
     * @param e 捕获到的异常信息
     * @return 返回到前端的信息
     */
    @ExceptionHandler(AuthorizationException.class)
    @ResponseBody
    public String authorizationException(Exception e){
        return "权限认证失败!";
    }
}
